<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>遮罩练习</title>
    <!-- <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.1.1/jquery.min.js"></script> -->
    <style>
        body {
            margin: 0px;
            padding: 0px;
            position: relative;
        }

        .d1 {
            width: 100px;
            height: 100px;
            line-height: 100px;
            margin: 0px auto;
            text-align: center;
            background-color: pink;
            cursor: pointer;
        }

        #zz {
            background-color: #00000030;
            display: none;
            position: absolute;
            top: 0px;
            left: 0px;
            width: 100%;
            height: 100%;
            z-index: 100;
        }

        #content {
            width: 100%;
            height: 100%;
            position: relative;
            /* background-color: red; */
        }

        #in {
            width: 200px;
            height: 200px;
            line-height: 200px;
            text-align: center;
            background-color: skyblue;
            position: absolute;
            left: 50%;
            margin-left: -100px;
            margin-top: -100px;
            top: 50%;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="d1" onclick=show()>
        点击展示遮罩
    </div>
    无情的萝卜头输入框：<input type="text" width="300px">
    <div id="zz">
        <div id="content">
            <div id="in" onclick="hide()">
                点击关闭遮罩
            </div>
        </div>
    </div>
    <script>

        // todo：显示遮罩
        function show() {
            const hei = document.documentElement.clientHeight;   // 可视区高度获取
            document.getElementById('zz').style.display = 'block';
            document.getElementById('zz').style.height = hei + 'px';
        }

        //  todo：隐藏遮罩
        function hide() {
            document.getElementById('zz').style.display = 'none';
        }

        /*
        遮罩小结：
        1：body元素作为父盒子
        2：遮罩的大盒子利用绝对定位脱离文档流，并利用z-index提升元素的层级，设置背景色为半透明状态即可
        3：遮罩的显示与隐藏：初始时遮罩隐藏display：none,通过切换遮罩的display：none/block，即可在显示隐藏间切换

        time： 2020/10/23 liukai

        */
    </script>
</body>

</html>